package de.fhhof.vinf.ssp.ticketcenter.beans;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

import javax.naming.NamingException;

import de.fhhof.vinf.ssp.ticketcenter.helpers.DatabaseManager;

public class TicketBean {
	
	private Integer ticketId;
	private Integer ticketCatId;
	private Integer ticketReqId;
	
	public Integer getTicketId() {
		return ticketId;
	}
	public void setTicketId(Integer ticketId) {
		this.ticketId = ticketId;
	}
	public Integer getTicketCatId() {
		return ticketCatId;
	}
	public void setTicketCatId(Integer ticketCatId) {
		this.ticketCatId = ticketCatId;
	}
	public Integer getTicketReqId() {
		return ticketReqId;
	}
	public void setTicketReqId(Integer ticketReqId) {
		this.ticketReqId = ticketReqId;
	}
	
	public void updateInDB() throws NamingException, SQLException{
		Connection con = DatabaseManager.getConnection();
		Statement stmt = con.createStatement();
		if(this.getTicketReqId() != null){
			stmt.executeUpdate("UPDATE tickets SET ticket_id = " + this.getTicketId() + ", ticket_category_id = " + this.getTicketCatId() + ", ticket_request_id = " + this.getTicketReqId() + " WHERE ticket_id = " + this.getTicketId());
		}
		con.close();
	}
	
	

}
